<?php

class Velden {
    public function inputTekst($veldData)  {
        return $this->_inputHTML($veldData,'text');        
    }
    
    public function inputWachtwoord($veldData) {
        return $this->_inputHTML($veldData,'password');
    }
    
    public function inputHidden($veldData) {
        return $this->_inputHTML($veldData,'hidden');
    }
    
    private function _inputHTML($veldData,$type='text') {
        $type = strtolower($type);
        $id = isset($veldData['id'])?$veldData['id']:'';
        $waarde = isset($veldData['waarde'])?$veldData['waarde']:''; 
        $placeholder = isset($veldData['placeholder'])?$veldData['placeholder']:'';
        $mode = isset($veldData['mode'])?$veldData['mode']:'';
        $label = isset($veldData['label'])?$veldData['label']:''; 
        
        if ($type == 'hidden') {
            $html = <<<EOD
                <div class="form-group">
                    <input type="{$type}" class="form-control formulierveld" id="{$id}" name="{$id}" {$mode} placeholder="{$placeholder}" value="{$waarde}">
                </div>
EOD;
        } else {
            $html = <<<EOD
                <div class="form-group">
                    <label for {$id}>{$label}</label>
                    <input type="{$type}" class="form-control formulierveld" id="{$id}" name="{$id}" {$mode} placeholder="{$placeholder}" value="{$waarde}">
                </div>
EOD;
        }
        
        return $html;
    }
    
    public function knop($veldData) {
        
    }
    
    public function checkboxGroep($veldData) {
        return $this->radioGroep($veldData,'checkbox');
    }
    
    public function radioGroep($veldData,$type='radio') {
        $inline = (isset($veldData['inline']) && $veldData['inline'])?'class="checkbox-inline"':'';
        $opties = $veldData['opties'];
        $mode = isset($veldData['mode'])?$veldData['mode']:'';
        $id = isset($veldData['id'])?$veldData['id']:'';
        
        $html = '<div class="form-group" id="'.$id.'">';
        foreach($opties as $optie) {
            $label = $optie['label'];
            $waarde = $optie['waarde'];
            $geselecteerd = (isset($optie['geselecteerd']) && $optie['geselecteerd'])?'checked="checked"':'';
            $html .= <<<EOD
                <label {$inline}>
                    <input type="{$type}" name="{$id}" class=" formulierveld" value="$waarde" {$geselecteerd} {$mode}> {$label}
                </label>
EOD;
        }
        $html .= '</div>';
        
        return $html;
    }   
    
}
